﻿CREATE PROCEDURE [dbo].[FindQuotePrices_SP]
@QuoteID int,
@CookieID int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT  QuoteLineItemID, MarketPriceEuro, SeasonalPriceEuro, Price, 
TotalPrice, OriginatingOEMSaillistID, BRP, 
case when OptionTotal is null then 0
else
OptionTotal 
end
as OptionTotal, 
(Select AXSymbol from Currency_Tbl where Currency_Tbl.CurrencyID=(Select CurrencyID from Quote_Tbl where Quote_Tbl.QuoteID=@QuoteID)) as CustomerCurrency,
(Select ExRate from Currency_Tbl where Currency_Tbl.AXSymbol=(Select BillingCurrency from UserDealer_Tbl where UserDealer_Tbl.CookieID=@CookieID)) as DealerExRate,
(Select BillingPriceID from UserDealer_Tbl where UserDealer_Tbl.CookieID=@CookieID) as BillingPrice,
(Select Max(Market_Tbl.CostFactor) from Market_Tbl where Market_Tbl.MarketID = 
(Select MarketID from Quote_Tbl where Quote_Tbl.QuoteID = QuoteLineItem_Tbl.QuoteID)) as MarketCF,
 (Select SeasonalPrice_Tbl.PriceFactor 
 from SeasonalPrice_Tbl where SeasonalPrice_Tbl.WeekNo = 
(Select DeliveryWeek from Quote_Tbl where Quote_Tbl.QuoteID = Quotelineitem_Tbl.QuoteID)) as SeasonalPF 
from QuoteLineItem_Tbl  where QuoteID=@QuoteID
END